package com.wz.project.bas.basType.controller;

import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.bas.basType.domain.BasType;
import com.wz.project.bas.basType.service.IBasTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类型表Controller
 * 
 * @author wz
 * @date 2022-02-11
 */
@Controller
@RequestMapping("/bas/basType")
public class BasTypeController extends BaseController
{
    private String prefix = "bas/basType";

    @Autowired
    private IBasTypeService basTypeService;

    @RequiresPermissions("bas:basType:view")
    @GetMapping()
    public String basType()
    {
        return prefix + "/basType";
    }

    /**
     * 查询类型表列表
     */
//    @RequiresPermissions("bas:basType:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasType basType)
    {
        startPage();
        List<BasType> list = basTypeService.selectBasTypeList(basType);
        return getDataTable(list);
    }

    /**
     * 导出类型表列表
     */
    @RequiresPermissions("bas:basType:export")
    @Log(title = "类型表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasType basType)
    {
        List<BasType> list = basTypeService.selectBasTypeList(basType);
        ExcelUtil<BasType> util = new ExcelUtil<BasType>(BasType.class);
        return util.exportExcel(list, "basType");
    }

    /**
     * 新增类型表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存类型表
     */
    @RequiresPermissions("bas:basType:add")
    @Log(title = "类型表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasType basType)
    {
        return toAjax(basTypeService.insertBasType(basType));
    }

    /**
     * 修改类型表
     */
    @GetMapping("/edit/{typeId}")
    public String edit(@PathVariable("typeId") String typeId, ModelMap mmap)
    {
        BasType basType = basTypeService.selectBasTypeById(typeId);
        mmap.put("basType", basType);
        return prefix + "/edit";
    }

    /**
     * 修改保存类型表
     */
    @RequiresPermissions("bas:basType:edit")
    @Log(title = "类型表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasType basType)
    {
        return toAjax(basTypeService.updateBasType(basType));
    }

    /**
     * 删除类型表
     */
    @RequiresPermissions("bas:basType:remove")
    @Log(title = "类型表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basTypeService.deleteBasTypeByIds(ids));
    }
}
